package com.lhy.controller;

import com.lhy.entity.Role;
import com.lhy.service.RoleService;
import com.lhy.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：罗昊宇
 * @Package：com.lhy.controller
 * @Project：springboot-mybatis-plus
 * @name：RoleController
 * @Date：2024/4/17 0017  19:10
 * @Filename：RoleController
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色相关接口")
public class RoleController {

    @Autowired
    private RoleService roleService;
    @ApiOperation(value = "角色分页查询")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "current",value = "当前页面",dataType = "int" ,required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页的条数",dataType = "int",required = true)
    })
    @GetMapping("/selectByPage/{current}/{pageSize}")
    public Result selectByPage(@PathVariable Integer current,@PathVariable Integer pageSize){

        return roleService.selectAll(current,pageSize);
    }

    @ApiOperation(value = "新增角色接口")
    @PostMapping("/insert")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role",value = "角色对象",dataType = "role",required = true)
    })
    public Result insertRole(@RequestBody Role role){

        return roleService.insertRole(role);
    }

    @ApiOperation(value = "修改角色接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role" ,value = "角色对象",dataType = "role" ,required = true)
    })
    @PutMapping("/update")
    public Result updateRole(@RequestBody Role role){

        return roleService.updateRole(role);
    }
    @ApiOperation(value = "根据ID删除角色接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "角色id",dataType = "int",required = true)
    })
    @DeleteMapping("/delete/{id}")
    public Result delteRole(@PathVariable Integer id){

        return roleService.deleteRole(id);
    }
}
